//app.js
App({
    onLaunch: function() {
        //调用API从本地缓存中获取数据
        //var logs = wx.getStorageSync('logs') || []
        //logs.unshift(Date.now())
        //wx.setStorageSync('logs', logs)
    },
    getUserInfo: function(cb) {
        var that = this
        if (this.globalData.userInfo) {
            typeof cb == "function" && cb(this.globalData.userInfo)
        } else {
            //调用登录接口
            wx.login({
                success: function(r) {
                    that.globalData.userCode = r.code;
                    wx.getUserInfo({
                        success: function(res) {
                            that.globalData.userInfo = res.userInfo
                            typeof cb == "function" && cb(that.globalData.userInfo)
                        }
                    })
                }
            })
        }
    },
    setUserSid: function(sid) {
        this.globalData.userSid = sid;
    },
    getUserSid: function() {
        return this.globalData.userSid;
    },
    setComId: function(comId) {
        this.globalData.comId = comId;
    },
    getComId: function() {
        return this.globalData.comId;
    },
    setOpenId(openId) {
        this.globalData.openId = openId;
    },
    getOpenId() {
        return this.globalData.openId;
    },
    getShop() {
        return this.globalData.shop;
    },
    setShop(shop) {
        this.globalData.shop = shop;
    },
    getHost() {
        return this.config.apiUrl;
    },
    setHost(host) {
        this.config.apiUrl = host;
    },
    getAlias() {
        return this.globalData.alias;
    },
    setAlias(alias) {
        this.globalData.alias = alias;
    },
    getIsFenxiao() {
        return this.globalData.is_fenxiao;
    },
    setIsFenxiao(is_fenxiao) {
        this.globalData.is_fenxiao = is_fenxiao;
    },
    getUserId() {
        return this.globalData.user_id;
    },
    setUserId(user_id) {
        this.globalData.user_id = user_id;
    },
    getRecommend() {
        return this.globalData.recommend;
    },
    setRecommend(recommend) {
        this.globalData.recommend = recommend;
    },
    globalData: {
        alias: '1',
        openId: null,
        userSid: '1',
        userInfo: null,
        shop: null, //当前店铺信息
        userCode: null,
        comId: null,
        is_fenxiao: null,
        user_id: null,
        recommend: null
    },
    config: {
        // apiUrl:'https://api.y.88ff.com'
        apiUrl: 'https://api.yun.taojinzi.cn'
    }
})